﻿@{
    Layout = null;
}
<script type="text/javascript">
    $(function () {
        $("#rptNormList").datagrid({
            url: "Norm/List/" + $("#FireWorkId").val() + "?r=" + Math.random(),
            onRowContextMenu: function (e, rowindex, rowData) {
                $("#rptNormList").datagrid('selectRow', rowindex);
                e.preventDefault();
                var row = $("#rptNormList").datagrid('getSelected');
                if (row) {
                    $('#menuNorm').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }
            }

        });
    });
    function Delete() {
        var row = $("#rptNormList").datagrid('getSelected');
        if (row) {
            $.messager.confirm('提醒', '<br>确定要删除<span style=\'color:#ff0000;\'>' + row.NormName + '</span>这种规格吗?', function (r) {
                if (r) {
                    form1.action = "Norm/Delete/" + row.Id;
                    $('#loading').window('open');
                    $("#form1").ajaxSubmit({ action: this.action, method: this.method });
                }
            });
        } else {
            $.messager.alert('错误', '<br>请先选择要删除的数据！', 'error');
        }
    }
    function Edit() {
        var row = $("#rptNormList").datagrid('getSelected');
        if (row) {
            $('#divNormEdit').window({ href: 'Norm/Edit/' + row.Id, title: '编辑规格' }).window('open');
        } else {
            $.messager.alert('错误', '<br>请先选择要编辑的数据！', 'error');
        }
    }
    function RequestError() {
        $.messager.alert('错误', '<br>请求失败！', 'error');
    }
    function formatStock(val, row) {
        if (val < 5) {
            return "<span style='color:#ff0000;'>"+val+"</span>";
        }
        else {
            return val;
        }
        
    }
    function formatDecimal(val, row) {
       return parseFloat(val).toFixed(2);
    }
</script>
<form id="form1" action="Norm/Delete" method="post" data-ajax-failure="RequestError"
data-ajax="true">
@Html.Hidden("FireWorkId", ((TechnicBlog.Models.FireWorkEntity)@ViewBag.FireWork).Id.ToString())
@Html.Hidden("BrandId", ((TechnicBlog.Models.BrandEntity)@ViewBag.Brand).Id.ToString())
<div style="padding: 10px;">
    <table id="rptNormList" class="easyui-datagrid" width="100%" cache="false" title="规格列表"
        singleselect="true" toolbar="#tb" iconcls="icon-list" rownumbers="true" pagination="true"
        pagelist="[10,20,25,30]">
        <thead>
            <tr>
                <th field="Id" width="50" align="center" hidden="true">
                    Id
                </th>
                <th field="NormName" width="200" align="left">
                    规格名称
                </th>
                <th field="BuyPrice" width="100" align="center" formatter="formatDecimal">
                    进价
                </th>
                <th field="SellPrice" width="100" align="center" formatter="formatDecimal">
                    售价
                </th>
                <th field="StockNumber" width="100" align="center" formatter="formatStock">
                    库存
                </th>
            </tr>
        </thead>
    </table>
</div>
<div id="tb" style="height: auto">
    <div style="padding: 5px; height: 26px;">
        <a href="javascript:void(0);" onclick="javascript:$('#divNormEdit').window({href:'Norm/Create/'+$('#FireWorkId').val(),title:'新增规格'}).window('open');"
            class="easyui-linkbutton" style="float: left;" iconcls="icon-add" plain="true">新增</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0)" onclick="Edit();" class="easyui-linkbutton" style="float: left;"
            iconcls="icon-edit" plain="true">编辑</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0);" class="easyui-linkbutton" style="float: left;" iconcls="icon-remove"
            plain="true" onclick="javascript:Delete();">删除</a>
        <div class="dialog-tool-separator">
        </div>
        <a href="javascript:void(0);" class="easyui-linkbutton" style="float: left;" iconcls="icon-back"
            plain="true" onclick="javascript:TreeLink('FireWork/Index/'+$('#BrandId').val(), '烟花管理');">返回</a>
    </div>
    <div style="padding: 5px; height: 26px; border-top: 1px solid #CCCCCC;">
        品牌名称:<span style="color:#ff0000;">@Html.Raw(((TechnicBlog.Models.BrandEntity)@ViewBag.Brand).BrandName)</span> &nbsp;&nbsp;
        烟花名称:<span style="color:#ff0000;">@Html.Raw(((TechnicBlog.Models.FireWorkEntity)@ViewBag.FireWork).FireWorkName)</span>
    </div>
</div>
<div id="menuNorm" class="easyui-menu" style="width: 120px;">
    <div iconcls="icon-edit" onclick="javascript:Edit();">
        编辑</div>
    <div class="menu-sep">
    </div>
    <div iconcls="icon-remove" onclick="javascript:Delete()">
        删除</div>
</div>
<div id="divNormEdit" class="easyui-window" resizable="false" title="新增规格" minimizable="false"
    cache="false" modal="true" closed="true" dosize="false" collapsible="false" maximizable="false"
    style="width: 450px; height: 300px; padding-top: 10px; text-align: center;">
</div>
</form>
